package com.ruoyi.web.controller.drugSystem.drugInfo;

import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.core.page.TableDataInfo;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.drugSystem.domain.SysChuku;
import com.ruoyi.drugSystem.service.ISysChukuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import javax.servlet.http.HttpServletResponse;
import java.util.List;

/**
 * 出库单位信息Controller
 *
 * @author ruoyi
 * @date 2023-03-07
 */
@RestController
@RequestMapping("/system/chuku")
public class SysChukuController extends BaseController
{
    @Autowired
    private ISysChukuService sysChukuService;

    /**
     * 查询出库单位信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:chuku:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysChuku sysChuku)
    {
        startPage();
        List<SysChuku> list = sysChukuService.selectSysChukuList(sysChuku);
        return getDataTable(list);
    }

    /**
     * 导出出库单位信息列表
     */
    @PreAuthorize("@ss.hasPermi('system:chuku:export')")
    @Log(title = "出库单位信息", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysChuku sysChuku)
    {
        List<SysChuku> list = sysChukuService.selectSysChukuList(sysChuku);
        ExcelUtil<SysChuku> util = new ExcelUtil<SysChuku>(SysChuku.class);
        util.exportExcel(response, list, "出库单位信息数据");
    }

    /**
     * 获取出库单位信息详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:chuku:query')")
    @GetMapping(value = "/{chukuId}")
    public AjaxResult getInfo(@PathVariable("chukuId") Long chukuId)
    {
        return success(sysChukuService.selectSysChukuByChukuId(chukuId));
    }

    /**
     * 新增出库单位信息
     */
    @PreAuthorize("@ss.hasPermi('system:chuku:add')")
    @Log(title = "出库单位信息", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysChuku sysChuku)
    {
        return toAjax(sysChukuService.insertSysChuku(sysChuku));
    }

    /**
     * 修改出库单位信息
     */
    @PreAuthorize("@ss.hasPermi('system:chuku:edit')")
    @Log(title = "出库单位信息", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysChuku sysChuku)
    {
        return toAjax(sysChukuService.updateSysChuku(sysChuku));
    }

    /**
     * 删除出库单位信息
     */
    @PreAuthorize("@ss.hasPermi('system:chuku:remove')")
    @Log(title = "出库单位信息", businessType = BusinessType.DELETE)
    @DeleteMapping("/{chukuIds}")
    public AjaxResult remove(@PathVariable Long[] chukuIds)
    {
        return toAjax(sysChukuService.deleteSysChukuByChukuIds(chukuIds));
    }
}